package commonClasses;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashMap;

public class Sections {
	public static void main(String[]args) throws IOException{
		
		FileReader fr = new FileReader("J:\\BC3_IMT_Training\\Sections.txt");
		BufferedReader fbr=new BufferedReader(fr);
		String str=fbr.readLine();
		while(str!=null){
			String[] split=str.split("\t");
			int l=split.length;
			System.out.println(split[1]+" "+split[0]);
			int ar[]=new int[l];
			ar[0]=0;
			HashMap<Integer, String> hm = new HashMap<Integer,String>();
			for(int i=1;i<l;i++){
				String spl[]=split[i].split(":");
				ar[i]=Integer.parseInt(spl[1]);
				hm.put(ar[i], spl[0]);
			}
			Arrays.sort(ar);
			new File("J:\\BC3_IMT_Training\\Sections\\"+split[0]).mkdir();
			PrintStream ps = new PrintStream("J:\\BC3_IMT_Training\\Sections\\"+split[0]+"\\"+split[0]+".txt");
			FileReader f = new FileReader("J:\\BC3_IMT_Training\\txt\\"+split[0]+".txt");
			BufferedReader fb=new BufferedReader(f);
			String st=fb.readLine();
			int x=1;
			int count=0;
			String s="";

			ps.print(split[0].substring(0, split[0].length()-1));
			do{

				if(count==ar[x]){
					if(!s.equals("")){
					ps.println(s+"\n");

					ps.print(hm.get(ar[x]));
					ps.println();
					ps.println();
					
					}
					x++;
					s="";
				}
				count++;
				if(s.endsWith("-")){
					s=s+st;
				}
				else{
				s=s+" "+st;
				}
				

				st=fb.readLine();
			}while(st!=null && x<(l));
			ps.println(s.trim());
			str=fbr.readLine();
		
		}
		
		
		
	}

}
